package com.gjh.ouygoing.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

@Slf4j
public abstract class ValidCodeUtil {
    public String ValidCodeCommon(HttpResponse response) throws Exception {
        int statusCode = response.getStatusLine().getStatusCode();
        String bodyAsString = EntityUtils.toString(response.getEntity());//得到我的这个微信端响应的详细信息
        if (statusCode == 200) {//判断微信响应的状态
            log.warn("响应成功，状态码是==>{}，申请返回结果==>{}",statusCode,bodyAsString);
        }else if(statusCode == 204){
            log.warn("响应成功");
        }else {//如果说不是204和200的状态码就说明存在异常
            log.error("请求信息失败，出现异常，状态码是==>"+statusCode+",申请返回的结果是==>"+bodyAsString);
            throw new Exception("请求信息失败，出现异常，状态码是==>"+statusCode+",申请返回的结果是==>"+bodyAsString);
        }
        return bodyAsString;
    }
}
